package com.magic.smartcity.view.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.magic.smartcity.R;

/**
 * @description:
 * @create: Create by Magic on 2022/2/1.
 */
public class WelcomeImageAdapter extends PagerAdapter {
    private static final String TAG = WelcomeImageAdapter.class.getSimpleName();

    private int[] images = null;

    public void setImages(int[] images){
        this.images = images;
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_welcome_image_page, container, false);
        if (images != null) {
            ImageView image = view.findViewById(R.id.image);
            image.setImageResource(this.images[position]);
        }
        container.addView(view);
        return view;
    }

    @Override
    public int getCount() {
        return images!=null?images.length:0;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }
}
